package com.assets.asset.annotation.aop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.assets.asset.mapper.TScrapMapper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 在新增报废的时候修改资产状态为报废
 */
@Component
@Aspect
public class TurnScrapTypeAOP {

    @Autowired
    TScrapMapper scrapMapper;

    @Around("@annotation(com.assets.asset.annotation.TurnScrapType))")
    public Object around(ProceedingJoinPoint point) throws Throwable {

        //获取当前
        Object[] args = point.getArgs();
        Object result = point.proceed(args);

        //拿到部门的id

        String toJSONString = JSON.toJSONString(args);
        System.out.println("toJSONString = " + toJSONString);

        //将部门的id转为所对应的名字

        String s = toJSONString.replace("]", "");
        String replace = s.replace("[", "");
        System.out.println(replace);

        JSONObject jsonObject = JSON.parseObject(replace);
        String assetCode = jsonObject.getString("assetCode");

        scrapMapper.updateAssetStatus(assetCode);


        return result;

    }

}
